package com.zhj.common.db.mysql.aop;

import com.zhj.common.db.mysql.page.Page;
import com.zhj.common.db.mysql.page.PageUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * @author zhj
 */
@Aspect
public class PageAOP {

    @Around("@annotation(com.zhj.common.db.mysql.annotation.Page)")
    public Object pageAOP(ProceedingJoinPoint joinPoint) throws Throwable {
        Page page = PageUtils.getPage();
        if (page != null) {
            page.setEnable(true);
        }
        try {
            return joinPoint.proceed();
        } finally {
            if (page != null) {
                page.setEnable(false);
            }
        }
    }
}
